package com.example.springboottest.example.thread.volatiletest;

import com.sun.btrace.BTraceUtils;

import java.util.concurrent.TimeUnit;

public class VolatileMain {
    public volatile int sum = 0;

    public String name = "";

    public static void main(String[] args) throws InterruptedException {
        VolatileMain volatileM = new VolatileMain();
        VolatileThread t1 = new VolatileThread(volatileM);
        VolatileThread t2 = new VolatileThread(volatileM);

        t1.start();
        t2.start();

        TimeUnit.SECONDS.sleep(2);

        System.out.println("sum:\t" + volatileM.getSum());

        System.out.println("name:\t" + volatileM.getName());
    }

    public Integer getSum() {
        return sum;
    }

    public void setSum(Integer sum) {
        this.sum = sum;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
